<?php
include_once 'config/env.config.php';
include_once 'config/db.'.Env_Config.'.config.php';
include_once 'op/base.function.php';

$table = "tbl_article_solr";

$skip = 1;
$loop = 60;
// $loop = 2700;
// $catid = 151;
// $catid = 143;

$options = array(PDO::ATTR_PERSISTENT=>FALSE);
$conn = new PDO('mysql:host='.dbHost.';dbname='.dbName, dbUser, dbPwd, $options);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn->exec('SET NAMES ' . dbCharset);

$solr_base_1 = 'http://10.30.11.80:8080/';
$solr_first_url_1 = $solr_base_1.'solr/db/dataimport?command=full-import';
$solr_then_url_1 = $solr_base_1.'solr/db/dataimport?command=delta-import';

$catid = '';
$affectNum = 0;

while($skip <= $loop){
	$RSSList = readElleRSS($catid, $skip);
	if(is_array($RSSList)){
		foreach ($RSSList as $value){
			$sql = "replace into $table (`id`, `title`, `content`, `category`, `tags`, `pv`, `modified`, `link`, `channel`, `pubDate`, `brand`, `url`) values ('{$value['id']}','{$value['title']}','{$value['content']}','{$value['category']}','{$value['tags']}', '{$value['pv']}', '{$value['modified']}', '{$value['link']}', '{$value['channel']}', '{$value['pubDate']}', '{$value['brand']}', '{$value['url']}')";				
			$affectNum += $conn->exec($sql);
		}
		
		// 导入solr数据
		file_get_contents($solr_then_url_1);
	}
	
	$skip++;
}

echo date('Y-m-d H:i:s').'||affectNum:'.$affectNum."\n";

?>